;(function($,COMP){
	
	if(COMP.voteSpecialCar){
		return;
	}
	
	COMP.voteSpecialCar = function(){
		
		//checkLogin
		$(".half-price-btn").on("click",function(){
			
			if(!parseInt($(".car-model","#vote-sel").val())){
				turnActive();
				return false;
			}
			window.backCallName = $(this).attr('btntype');
			checkLogin(MALL.accountQuickBase,'B');
			
		});
		
		//校验select
		function verify(a,b){
			if(a[0].value==""||a[0].value==0){
				$(".warning-tips").text(b);
				$(".warning-tips").show();
				a.parent().addClass("sel-bor-warn");
			}else{
				$(".warning-tips").hide();
				a.parent().removeClass("sel-bor-warn");
			}
		};
		var oCarBrand=$(".car-brand","#vote-sel");
		var oCarSeries=$(".car-series","#vote-sel");
		var oCarModel=$(".car-model","#vote-sel");
	
		oCarBrand.on("change",function(){
			verify(oCarBrand,"请选择品牌");	
		});
		oCarSeries.on("change",function(){
			verify(oCarSeries,"请选择车系");
		})
		oCarModel.on("change",function(){
			verify(oCarModel,"请选择车型");
		});
		//按钮满足条件才可投票否则提示
		function turnActive(){
			if(parseInt(oCarBrand.val())&&parseInt(oCarSeries.val())&&parseInt(oCarModel.val())){
				$(".warning-tips").hide();
			}else{
				$(".warning-tips").text("请选择你所要的特价车（品牌、车型、车系）");
				$(".warning-tips").show();
			}
		};
		
		
		//发起半价车
		window.halfPrice = function(){
			//event.stopPropagation();
			if(parseInt(oCarModel.val())){
				//提交数据
				var velSeriesName = oCarSeries.find("option").not(function(){ return !this.selected }).text();
				var velModelName = oCarModel.find("option").not(function(){ return !this.selected }).text();
				var modelName=velSeriesName+'-'+velModelName;
				var param={};
				param['velModelName']  = velModelName;
				param['velSeriesName']  = velSeriesName;
				param['velSeriesId']  = oCarSeries.find("option").not(function(){ return !this.selected }).val();
				param['velModelId']  = oCarModel.find("option").not(function(){ return !this.selected }).val();
				param['velBrandId']  = oCarBrand.find("option").not(function(){ return !this.selected }).val();
				param['brandName']  = oCarBrand.find("option").not(function(){ return !this.selected }).text();
				param['cityId']  = _getCookie("city.id");
				param['activityName'] = $(".half-price-btn",".sel-grey").attr("activityName");
				param['activityNo'] = $(".half-price-btn",".sel-grey").attr("activityNo");
				param['areaType'] = $(".half-price-btn",".sel-grey").attr("areaType");
				param['promotionId'] = $(".half-price-btn",".sel-grey").attr("promotionId");
				$.ajax({
					url:"/promotion/saveProUserInfo.htm",
					type: "POST",
					data: param,
					dataType: "json",
					contentType: "application/x-www-form-urlencoded; charset=utf-8",
					success: function(data){
						if(data>0)
						{
							ECar.easyDialog.open({
								callback : function(){
									window.location.reload();
								},
								container : {
									header : '提示',
									content : '<div style="text-align:center">发起成功，谢谢参与！</div>'
								}
								//callback:isLogin
							});
						}else
							{
								ECar.easyDialog.open({
									callback : function(){
										window.location.reload();
									},
									container : {
										header : '提示',
										content : '<div style="text-align:center">本期你已发起过特价车，下期再来吧</div>'
									}
									//callback:isLogin
								});
							}
						
					},
					error: function(){
						ECar.easyDialog.open({
							callback : function(){
								window.location.reload();
							},
							container : {
								header : '提示',
								content : '<div style="text-align:center">未提交成功，请稍后再试</div>'
							}
						});
					}
				});
			}else{
				turnActive();
				return false;
			}
		};
	
	};
	
	COMP.voteSpecialCar();

})(jQuery,window.COMP||(window.COMP={}));
